<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>教师管理</title>
	<link rel="stylesheet" href="/css/common2.css">
	<link rel="stylesheet" href="/css/popup.css">
	<style>
		.search {
			margin-top: 1px;
			position: absolute;
			right: 100px;
		}

		.search_img {
			position: absolute;
			margin-top: 1px;
			right: 3%;
		}

		.table tbody tr td {
			max-height: 225px !important;
			overflow: hidden;
		}

		.one {
			width: 6%;
		}

		.two {
			max-width: 165px;
			width: 16%;
		}

		.three {
			min-width: 100px;
			width: 9%;
		}

		.nickname {
			width: 100px;
			text-align: left;
			margin-right: 35px;
			display: inline-block;
			text-overflow: ellipsis;
			overflow: hidden;
			white-space: nowrap;
		}

		.header {
			width: 35px;
			height: 35px;
			display: inline-block;
			border-radius: 50%;
		}

		.untying {
			position: absolute;
			right: 0;
			bottom: 0;
			display: inline-block;
			font-size: 14px;
			color: #9F9F9F;
		}

		.importall {
			margin-left: 50px;
			margin-top: 20px;
		}

		.long-background-img {
			width: 120px;
			height: 35px;
			margin-left: 10px;
			background: url("../image/enter_longer.png") no-repeat center center !important;
		}

		.w_right {
			float: right;
			display: flex;
			align-items: center;
		}

		.w_right .pagination {
			margin: 0;
		}
	</style>
</head>

<body>
	<div id="vue-root" style="margin-top: 30px;">
		<div class="add" v-if="able.add">
			<a href="educational_teacher_item.html" style="color: white">添加教师</a>
		</div>
		<div class="refresh" onclick="location.reload()">刷新</div>

		<select class="search" v-model="search.bound" style="right: 260px">
			<option :value="undefined">请选择是否有绑定</option>
			<option :value="true">是</option>
			<option :value="false">否</option>
		</select>

		<input placeholder="请输入姓名" class="search" v-model="search.name" style="height: 33px;">
		<img src="../image/search.png" height="35" width="35" alt="" class="search_img" @click="getData0">
		<form enctype="multipart/form-data" id="form" ref="form" style="display: none;">
			<input type="file" name="file" id="file" @change="importExcel" ref="file"
				accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel">
		</form>

		<div class="table">
			<table class="table_top">
				<thead>
					<tr>
						<th class="one">
							<input type="checkbox" class="check-box" v-model="all">
						</th>
						<th class="one">序号</th>
						<th class="three">姓名</th>
						<th class="three">头像</th>
						<th class="one">性别</th>
						<th class="two">绑定者</th>
						<th class="two">手机</th>
						<th class="two">绑定码</th>

						<th class="three">编辑/删除</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(teacher,index) in list" :key="teacher.id">
						<td class="one">
							<input type="checkbox" class="check-box" v-model="teacher.checked">
						</td>
						<td class="one"><span v-text="index+1"></span></td>
						<td class="three" v-text="teacher.name"></td>
						<td class="three photo">
							<img :src="getImg(teacher.avatar)" alt="" v-if="teacher.avatar">
						</td>
						<td class="one" v-text="teacher.sex?'男':'女'"></td>
						<td class="two">
							<div v-if="teacher.accountId">
								<img :src="teacher.headimgurl.replace('http://','https://')" alt="" class="header"
									v-if="teacher.headimgurl">
								<div class="nickname" v-text="teacher.nickname"></div>
								<button v-if="able.edit" class="untying" @click="unbind(teacher)">解绑</button>
							</div>
						</td>
						<td class="one" v-text="teacher.phone"></td>
						<td class="two" v-text="teacher.bindCode"></td>

						<td class="three">
							<div class="option">
								<div class="edit-icon option-icon" v-if="able.edit"
									style="position: absolute; left: 20%; top: 30%;">
									<a :href="'educational_teacher_item.html?id='+teacher.id">
										<img class="img" src="../image/edit.png" height="20" width="20"
											onmouseover="this.src='../image/edit_light.png'"
											onmouseout="this.src='../image/edit.png'" />
									</a>
								</div>
								<div class="delete-icon option-icon" v-if="able.del" @click="del([teacher.id])"
									style="position: absolute; right: 20%; top: 30%;">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'">
								</div>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br>
		<!-- <div class="delete" @click="batchDelete" v-if="able.del">批量删除</div> -->
		<a href="/excel/teacher.xls" v-if="able.import">
			<div class="delete long-background-img">下载导入模板</div>
		</a>
		<label v-if="able.import" class="delete long-background-img" for="file">批量导入老师</label>
		<div  v-if="able.export" class="delete long-background-img" @click="exports">批量导出老师</div>
		<div class="w_right">
			总共{{total}}条记录
			<ul class="pagination" v-if="pages>1">
				<li>
					<a v-if="pageNum!=1" @click="pageNum=1">«</a>
					<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
					<a v-text="pageNum"></a>
					<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
					<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
				</li>
			</ul>
		</div>
	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>
		var schoolId = top_params().id;
		var app = new Vue(merge({
			data: {
				urls: {
					list: '/pc/teacher/list/' + schoolId,
					del: '/pc/teacher/del',
					imports: '/pc/teacher/import2/' + schoolId
				},
				popup: false,
				teacherId: null
			},
			created: function () {
				if (!schoolId) {
					alert('未知学校');
					throw '未知学校';
				}
				this.schoolId = schoolId;
				this.getData();

				abled('teacherAccount', this);
			},
			methods: {
				getImg: function (pic) {
					if (!pic) return null;
					return '/static/' + this.schoolId + '/teacher/' + pic;
				},
				unbind: function (teacher) {
					if (!confirm('确定解除此绑定吗？')) return;
					axios.post('/pc/teacher/unbind/' + teacher.id).then(function (res) {
						alert('成功');
						teacher.nickname = null;
						teacher.headimgurl = null;
					});
				},
				exports: function () {
					var q = Qs.stringify(this.search);
					if (q) q = '?' + q;
					location.href = '/pc/teacher/export/' + this.schoolId + q;
				}
			}
		}));
	</script>
</body>

</html>